package com.idp.app.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.idp.app.dto.AppVersionDto;
import com.idp.app.dto.AppVersionSearchDto;
import com.idp.app.service.AppVersionService;
import com.idp.common.base.BaseController;
import com.idp.common.model.PageModel;
import com.idp.common.model.ResultModel;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 版本维护Controller
 * @author King
 */
@Api(tags="版本维护")
@RestController
@RequestMapping("/appVersion/")
public class AppVersionController extends BaseController {

	@Autowired
	private AppVersionService appVersionService;

	/**
	 * 分页查询
	 * @param appVersionSearchDto
	 * @return
	 */
	@ApiOperation(value="分页查询")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "page", value = "页数", paramType = "query", required = true, defaultValue = "1"),
			@ApiImplicitParam(name = "rows", value = "每页行数", paramType = "query", required = true, defaultValue = "10")
	})
	@PostMapping("findByPage")
	public ResultModel<PageModel<AppVersionDto>> findByPage(@RequestBody AppVersionSearchDto appVersionSearchDto) {
		return ResultModel.success(appVersionService.findByPage(appVersionSearchDto));
	}

	/**
	 * 通过主键查询
	 * @param appVersionDto
	 * @return
	 */
	@ApiOperation(value="通过主键查询")
	@ApiOperationSupport(includeParameters = {"appVersionDto.id"})
	@PostMapping("getById")
	public ResultModel<AppVersionDto> getById(@RequestBody AppVersionDto appVersionDto) {
		return ResultModel.success(appVersionService.getById(appVersionDto.getId()));
	}

	/**
	 * 新增
	 * @param appVersionDto
	 * @return
	 */
	@ApiOperation(value="新增")
	@PostMapping("add")
	public ResultModel add(@RequestBody AppVersionDto appVersionDto) {
		appVersionService.add(appVersionDto);
		return ResultModel.success("新增成功", null);
	}

	/**
	 * 修改
	 * @param appVersionDto
	 * @return
	 */
	@ApiOperation(value="修改")
	@PostMapping("update")
	public ResultModel update(@RequestBody AppVersionDto appVersionDto) {
		appVersionService.update(appVersionDto);
		return ResultModel.success("修改成功", null);
	}

	/**
	 * 删除
	 * @param appVersionDto
	 * @return
	 */
	@ApiOperation(value="删除")
	@ApiOperationSupport(includeParameters = {"appVersionDto.id"})
	@PostMapping("delete")
	public ResultModel delete(@RequestBody AppVersionDto appVersionDto) {
		appVersionService.delete(appVersionDto.getId());
		return ResultModel.success("删除成功", null);
	}

	/**
	 * 检测版本
	 * @param appVersionDto
	 * @return
	 */
	@ApiOperation(value="检测版本")
	@ApiOperationSupport(includeParameters = {"appVersionDto.versionCode", "appVersionDto.appType"})
	@PostMapping("checkVersion")
	public ResultModel<AppVersionDto> checkVersion(@RequestBody AppVersionDto appVersionDto) {
		Integer versionCode = appVersionDto.getVersionCode();
		String appType = appVersionDto.getAppType();
		return ResultModel.success(appVersionService.checkVersion(versionCode, appType));
	}

}
